package com.hmdp.Interceptor;

import com.hmdp.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 刘宇
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1. 判断是否进行拦截即可
        if(UserHolder.getUser()==null){
            //没有设置状态码
            response.setStatus(401);
            //拦截
            return false;
        }
        return true;
    }
}
